import time
import yaml
from selenium.webdriver.common.by import By
from selenium.webdriver.support.select import Select

from page.basePage import basePage

with open(r'D:\PycharmProjects\ecShop\autoTest\driver\elements.yml','r',encoding='utf-8') as file:
    elements_config = yaml.safe_load(file)

class commentsPage(basePage):
    url = 'http://localhost:8800/ecshop/'
    login_btn1 = By.XPATH, elements_config['login_page']['login_btn1']
    username_frm = By.XPATH, elements_config['login_page']['username_frm']
    pwd_frm = By.XPATH, elements_config['login_page']['pwd_frm']
    login_btn2 = By.XPATH, elements_config['login_page']['login_btn2']

    commodity_btn = By.XPATH,elements_config['comments_page']['commodity_btn']
    text_frm = By.XPATH,elements_config['comments_page']['text_frm']
    tj_btn = By.XPATH,elements_config['comments_page']['tj_btn']

    def click_login1(self):
        self.find_Element(self.login_btn1).click()

    def send_username(self,username):
        self.find_Element(self.username_frm).send_keys(username)

    def send_pwd(self,password):
        self.find_Element(self.pwd_frm).send_keys(password)

    def click_login2(self):
        self.find_Element(self.login_btn2).click()

    def click_commodity(self):
        self.find_Element(self.commodity_btn).click()

    def send_text(self,text):
        self.find_Element(self.text_frm).send_keys(text)

    def click_tj(self):
        self.find_Element(self.tj_btn).click()

    def commenting(self,username,password,text):
        self.open(self.url)
        time.sleep(2)
        self.click_login1()
        self.send_username(username)
        self.send_pwd(password)
        self.click_login2()
        time.sleep(5)
        self.click_commodity()
        self.send_text(text)
        self.click_tj()
        time.sleep(2)






